<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>标签类型映射</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">

		<!--标准mui.css-->
		<link rel="stylesheet" href="css/mui.min.css">
		<!--App自定义的css-->
		<!--<link rel="stylesheet" type="text/css" href="css/app.css" />-->
		<style>
			.mui-card .mui-control-content {
				padding: 10px;
			}			
			.mui-control-content {
				height: 150px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">标签类型映射</h1>
		</header>
		<div class="mui-content">
			<div style="padding: 10px 10px;">
				<div id="divTab" class="mui-segmented-control">
					<!--
					 <a class="mui-control-item mui-active" href="#item1" >待办公文（8）</a>
					 -->
				</div>
			</div>
			<div id="divTabContent">
				
				<div id="item1" class="mui-control-content mui-active">
					<!--
					<div class="mui-input-row">
						<h4 style="margin-top: 10px; float: left;">标签：</h4>
						<div class="mui-pull-right">
							<button type="button" class="mui-btn mui-btn-success mui-icon mui-icon-plus mui-right" style="width: 80px;" onclick='Map_List("")'>编辑</button>
						</div>
					</div>
					<div>
					
					 <button type="button" class="mui-btn mui-btn-primary mui-btn-outlined" onclick="TagType_Select()">
						操作1
					 </button>
					
					</div>	-->
				</div>				
			</div>			
		</div>
		<script src="js/mui.min.js"></script>
		<script src="js/jquery.min.js"></script>
		<script src="libs/lib.js"></script>
		<script>
			mui.init({
				swipeBack: true //启用右滑关闭功能
			});
			
			(function($) {
				$('#scroll').scroll({
					indicators: true //是否显示滚动条
				});
				
				Enum_TagType_List();
			})(mui);
			
			function Enum_TagType_List(){
				var param = {  
				  Param: "ColorLargeType,DirectionLargeType,LuckyLargeType,SeasonLargeType,WorldLargeType"
				}
				Core.Post("Enum/TypeList", param, function(result, status){
					if(result.errorMsg){
						Core.Msg.Alert(result.errorMsg);
						return;
					}
					if(!result.data)
						return;
					if(result.data.length == 0)
						return;
					
					var list = result.data;					
					var html = "", htmlContent = "";	
					
					var defaultIndex = 0;
					var mapType = Core.Tool.GetUrlParam("mapType");
					if(mapType){
						for(var i=0;i<list.length;i++){
							if(list[i].enumId == mapType){
								defaultIndex = i;
								break;
							}
						}
					}
					
					for(var i=0;i<list.length;i++){
						if(i == defaultIndex){
							html += "<a class='mui-control-item mui-active' href='#"+list[i].enumId+"' onclick=\"Enum_Tag_List('"+list[i].enumId+"')\">"+list[i].enumValue+"</a>";
							htmlContent += " <div id='"+list[i].enumId+"' class='mui-control-content mui-active'></div> ";
							continue;
						}
						html += "<a class='mui-control-item' href='#"+list[i].enumId+"' onclick=\"Enum_Tag_List('"+list[i].enumId+"')\">"+list[i].enumValue+"</a>";	
						htmlContent += " <div id='"+list[i].enumId+"' class='mui-control-content'></div> ";
					}
					document.getElementById("divTab").innerHTML = html;
					document.getElementById("divTabContent").innerHTML = htmlContent;
					
					Enum_Tag_List(list[defaultIndex].enumId)
				});
			}
			
			function Enum_Tag_List(parentId){
				var param = {  
				  Param: {
					  EnumParentId: parentId
				  }
				}
				Core.Post("Enum/List", param, function(result, status){
					if(result.errorMsg){
						Core.Msg.Alert(result.errorMsg);
						return;
					}
					
					var list = result.data;
					var html = "";
					for(var i=0;i<list.length;i++){
						html +=" 	<div class='mui-input-row' style='margin-top: 20px;'> ";
						html +=" 		<h4 style='margin-top: 10px; float: left;'>"+list[i].enumValue+"</h4> ";
						html +=" 		<div class='mui-pull-right'> ";
						html +=" 			<button type='button' class='mui-btn mui-btn-success mui-icon mui-icon-plus mui-right' style='width: 80px;' onclick=\"Map_Edit_BindId('"+parentId+"','"+list[i].enumId+"')\">编辑</button> ";
						html +=" 		</div> ";
						html +=" 	</div> ";
						html +=" 	<div id='div_content_"+list[i].enumId+"'> ";
						html +=" 	</div>	 ";
					}					
					document.getElementById(parentId).innerHTML = html;
					
					Map_List(parentId);
				});
			}
			
			function Map_List(parentId){
				var param = {
					Param:{
						MapType: parentId
					}
				}
				Core.Post("Map/List", param, function(result, status){
					if(result.errorMsg){
						Core.Msg.Alert(result.errorMsg);
						return;
					}
					var list = result.data;
								
					var BindIds = [];
					for(var i=0;i<list.length;i++){
						if(BindIds.indexOf(list[i].bindId) == -1)
							BindIds.push(list[i].bindId);
					}
						
					for(var i=0;i<BindIds.length;i++){
						var html = "";	
						for(var j=0;j<list.length;j++){
							if(list[j].bindId != BindIds[i])
								continue;
							html += "<button type='button' class='mui-btn mui-btn-primary mui-btn-outlined' style='margin-left: 10px;'>"+list[j].dataName+"</button>";
						}
						document.getElementById("div_content_"+BindIds[i]).innerHTML = html;
					}
				});
			}		
				
			function Map_Edit_BindId(mapType, bindId){
				window.location.href = "map_tagtype_edit.html?bindId="+bindId+"&mapType="+mapType;
			}
		</script>

	</body>

</html>